package com.ap.core.bulkupload.handler.impl;

import java.io.InputStream;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ap.core.bulkupload.handler.BulkUploadHandler;
import com.ap.core.bulkupload.info.BulkUploadBaseInfo;
import com.ap.core.bulkupload.info.builder.BulkUploadInfoBuilder;
import com.ap.core.bulkupload.types.BulkFileUploadEnum;
import com.ap.core.bulkupload.types.BulkUploadInfoBuilderType;
import com.ap.core.exception.APCoreException;

/**
 * The Class DefaultBulkUploadHandler.
 * @author Siva.Pochana
 */
public class DefaultBulkUploadHandler implements BulkUploadHandler {
	
	/** The log. */
	private static final Logger log = LoggerFactory.getLogger(DefaultBulkUploadHandler.class);
	
	/** The bulk upload info builder map. */
	private Map<String , BulkUploadInfoBuilder> bulkUploadInfoBuilderMap;
	
	/* (non-Javadoc)
	 * @see com.ap.core.bulkupload.handler.BulkUploadHandler#populateInfo(com.ap.core.bulkupload.types.BulkFileUploadEnum, java.io.File, com.ap.core.bulkupload.types.BulkUploadInfoBuilderType)
	 */
	@Override
	public BulkUploadBaseInfo populateInfo(BulkFileUploadEnum bulkFileUploadEnum, 
			InputStream inputStream, BulkUploadInfoBuilderType infoBuilderType) throws APCoreException {
		try {
			return bulkUploadInfoBuilderMap.get(bulkFileUploadEnum.name()+"-"+infoBuilderType.name()).populateInfo(inputStream);
		}catch(APCoreException e) {
			log.error("Exception occurred while processsing BulkFileUploadEnum ["+bulkFileUploadEnum.name()+"]  " +
					"and BulkUploadInfoBuilderType ["+infoBuilderType.name()+"] and Error Msg ["+e.getMessage()+"]");
			throw e;
 		}  catch(Exception e) {
			log.error("Exception occurred while processsing BulkFileUploadEnum ["+bulkFileUploadEnum.name()+"]  " +
					"and BulkUploadInfoBuilderType ["+infoBuilderType.name()+"] and Error Msg ["+e.getMessage()+"]");
			throw new APCoreException(e);
		}
	}

	/**
	 * Sets the bulk upload info builder map.
	 *
	 * @param infoBuilderMap the info builder map
	 */
	public void  setBulkUploadInfoBuilderMap(Map<String, BulkUploadInfoBuilder> infoBuilderMap) {
		this.bulkUploadInfoBuilderMap = infoBuilderMap;
	}
	
}
